const VITE_APP_PROXY_URL = import.meta.env.VITE_APP_PROXY_URL;

export function getDom(dom: string = '', instance: any = {}): any {
    return new Promise((resolve: any, reject: any) => {
        const query: any = uni.createSelectorQuery().in(instance.proxy);
        
        if(!dom) return reject('节点不能为空');

        query.select(dom).boundingClientRect((data: any) => {
            resolve(data);
          }).exec();
    })
}

export function getSystemInfo(): any {
    return new Promise((resolve, reject) => {
        uni.getSystemInfo({
            success: (res) => {
                resolve(res || {});
            },
            fail: (err) => {
                reject(err);
            }
          });
    })
}

export function checkPhoneNumber(phone: string = '') {
    let per = /^1[3-9]\d{9}$|^0\d{2,3}-\d{7,8}$/;
    return per.test(phone);
}

export function joinUrl(url: string = '') {
    return VITE_APP_PROXY_URL + url;
}